
//进行分配评委时，需要项目的一些字段
var proId = 0;       //项目的id
var proName = "";    //项目的名称
var proProposer = "";   //项目的申请人
var proposerMobile = "";  //项目申请人的手机号

var adminLinkMan = "";
var adminOrgName = "";

var formatterOper = function(value,row,id){
    return ['<a href="javascript:void(0)" class="fenping" style="color:blue">分配评委</a>&nbsp&nbsp&nbsp&nbsp'+'<a href="javascript:void(0)"' +
    ' class="chakan" style="color:blue">查看</a>&nbsp&nbsp&nbsp&nbsp'+'<a href="javascript:void(0)" class="jiafen" style="color:blue">加分</a>'].join('');
}

var isAddScoreFor = function(value,row,id){
    if(value>0){
        return ['<span style="color:blue">是</span>'].join('');
    }else{
        return ['<span>否</span>'].join('');
    }
}

//下面是发送一个ajax的请求来查询所有的园区
$.post($().AbsUrlParse("/web/park/findParks"),
    {
    },
    function(data){
        var selectOpt = "<select name='parkName' id='parksExport' style='width:220px' class='form-control'><option value=''>---请选择园区---</option>";
        for(var i=0;i<data.res.data.length;i++){
            var parkName = data.res.data[i].parkName;
            selectOpt+='<option value='+parkName+'>'+parkName+'</option>'
        };
        selectOpt+="</select>"
        $("#parkss").html(selectOpt);

    }
);

//颜色的格式化
var colorFormatter = function(value,row,index){
    if(value=="审核通过"){
        return ['<span style="color: green">' + value + '</span>'].join('');
    }
}

var isSigned = function(value,row,index){
    if(value==1){
       return '<a herf="javascript:void(0)" onclick="merge('+proId+','+row.id+')" style="color:red">不可分配</a>';
    }else{
        return '<span style="color:green">可分配</span>'
    }
}

//下面是点击查询按钮
bindClick("#btnSearch",function(){

    //下面获得各个查询时的内容
    var hangYe = $("select[name=hangYe]").val();
    var parkName = $("select[name=parkName]").val();
    var multiSearch = $("input[name=multiSearch]").val();
    var url =$().AbsUrlParse("/web/userproject/secondNameList?hangYe="+hangYe+"&parkName="+parkName+"&multiSearch="+multiSearch);
    $("#table").bootstrapTable("refresh", {"url": url});

});

window.operateEvents = {

    'click .surePingWeiEnd':function(e,value,row,index) {

    },

    'click .fenping': function (e, value, row, index) {
        //把上次对admin的查询进行清空
        $("select[name=pingweiS]").val("");
        $("input[name=zhanghaoS]").val("");
        $("input[name=jigouS]").val("");
        $("input[name=lianxirenS]").val("");

        //下面是得到项目的信息
        proId = row.id;
        proName = row.declareProject;
        proProposer = row.proposer;
        proposerMobile = row.proposerMobile;

        showModel("slidingmenu", function () {

        });
        var url = $().AbsUrlParse("/web/ensadmin/mutilSearch?proId="+proId);
        $("#table_1").bootstrapTable("refresh", {"url": url});

    },

    'click .chakan':function(e, value, row, index){
        showModel("chakanModel", function (){
            setRowToFrm("chakan",row);
        });
    },
    //进行加分
    'click .jiafen':function (e, value, row, index) {
        proId = value;
        showModel("jiafen");
    }

}

var surePingweiFormatter = function (value,row,index){
    return ['<input type="checkbox" value='+row.orgName+'&'+row.linkman+'&'+row.id+' class="surePingWeiEnd" style="width:18px;height:18px" />'];
}

bindClick("#queding",function(){
  var adminLinkManAndOrgName =[];

  $("input[class=surePingWeiEnd]:checked").each(function(){
      adminLinkManAndOrgName.push($(this).val())
  });


    if(adminLinkManAndOrgName==""){
        comment.showOperationTips("没有选中的选项，不能提交！",function(){

        });
    }
    else{
        $.post($().AbsUrlParse('/web/ensadmin/pwend'), {
            proId:proId,
            proName1:proName,
            proProposer:proProposer,
            proposerMobile:proposerMobile,
            adminLinkManAndOrgName:adminLinkManAndOrgName.toLocaleString(),
            roleId:roleId,
            roleName:roleName
        }, function (data) {
            var url = $().AbsUrlParse("/web/ensadmin/mutilSearch?proId="+proId);
            $("#table_1").bootstrapTable("refresh", {"url": url});
            hint("分配操作成功");
        });
    }

});

//s_admin表的筛选
bindClick("#btnS",function(){

    var pingweiS = $("select[name=pingweiS]").val();
    var zhanghaoS = $("#zhanghaoS").val();
    var jigouS = $("#jigouS").val();
    var lianxirenS = $("#lianxirenS").val();


    var url = $().AbsUrlParse("/web/ensadmin/multiSearchAdmins?pingweiS="+pingweiS+"&zhanghaoS="+zhanghaoS+"&jigouS="+jigouS+"&lianxirenS="+lianxirenS);
    $("#table_1").bootstrapTable("refresh", {"url": url});
});


function merge(proId,judgeId){

    comment.showOperationTips("是确认要解除分配吗？",function(){
        $.post($().AbsUrlParse("/web/projectallocation/unsigned"),{
            proId:proId,
            judgeId:judgeId
          },function(data){
            var url = $().AbsUrlParse("/web/ensadmin/mutilSearch?proId="+proId);
            $("#table_1").bootstrapTable("refresh", {"url": url});

            if(data.res.data.isScore=="是"){
                hint("评委已给项目打过分，不能解除分配");
            }else{
                hint("已解除成功");
            }
         });
    });
}

//进行全部的项目与评委的分配
bindClick("#bntAllSign",function(){
    comment.showOperationTips("您确认要把所有的项目与评委进行匹配吗？",function(){
        $.post($().AbsUrlParse("/web/userproject/allSign")
            ,{
                roleName:roleName
            },function(data){
                if(data.state==true){
                    if(data.res.code==40000){
                        closeModel("finddetail-div");
                        hint("完成所有项目与评委的匹配");
                    }else{
                        hint(data.res.msg);
                    }
                }else{
                    hint(data.msg);
                }
            }
        );
    });
});

bindClick("#jiafenSure",function(){



    var jiafenren = $("#jiafenren").val();
    var jiafenreason = $("#jiafenreason").val();
    var jiafenzhi = $("#jiafenzhi").val();



    if(parseInt(jiafenzhi)<=0){
        hint("加分数值不能小于0");
        return false;
    }




    comment.showOperationTips("您确定要对该项目进行加分吗？",function(){
        $.post($().AbsUrlParse("/web/userproject/jiafenSure"),{
            jiafenren:jiafenren,
            jiafenreason:jiafenreason,
            jiafenzhi:jiafenzhi,
            proId:proId
        },function(data){
            if(data.state==true){
                if(data.res.code==40000){
                    closeModel("finddetail-div");
                    hint("加分成功");
                }else{
                    hint(data.res.msg);
                }
            }else{
                hint(data.msg);
            }
        });
    })
});



bindClick("#btnExport",function(){

    var parksExport = $("#parksExport").val();
    var hangyeExport = $("#hangyeExport").val();
    var multiExport = $("#multiExport").val();

    $.post($().AbsUrlParse("/web/userproject/exportSecondNameList"),{
        parksExport:parksExport,
        hangyeExport:hangyeExport,
        multiExport:multiExport
    },function(data){
        if (data.state == true) {
            if (data.res.code == 40000) {
                hint("导出成功");
                var a = document.createElement("a");
                a.href = $().AbsUrlParse("/excel/" + data.res.data);
                a.click();
            } else {
                hint(data.res.msg);
            }
        } else {
            hint(data.msg);
        }
    });
});
